home *** CD-ROM | disk | FTP | other *** search
- /* execchld.c--- BIBLE pp. 77-83 */
-
- /* ======================= CHILD ========================= */
- /* Must be in file named: CHILD.EXE */
- #include <stdio.h>
- #include <dos.h>
- #include <string.h>
- typedef struct TEST_DATA
- {
- char name[20];
- int n;
- double x;
- } TEST_DATA;
- /* CHILD: First argument is program name,
- * Second one tells us how child is invoked
- * Third argument is an address in the form
- * SSSS:0000 (segment:offset). This is the
- * address of a data structure allocated in
- * the parent. */
- static char far *cname = "CHILD";
- main(int argc, char **argv, char **envp)
- {
- char ***p_table;
- TEST_DATA far *pdata;
- void far *p_s1;
- void far *p_s2;
- printf("CHILD: received %d arguments\n", argc);
- if(argc < 3)
- {
- printf("not enough arguments\n");
- exit(1);
- }
- printf("CHILD invoked by a %s call.\n",argv[1]);
-
- /* Now print the environment passed to CHILD */
- printf("==== CHILD: Environment contains ====\n");
- for(p_table = envp; *p_table != NULL; p_table++)
- printf("%s\n", *p_table);
-
- /* Read in address of parent's data from argv[2] */
- sscanf(argv[2], "%Fp", (void far *)&pdata);
- printf("In child: name = %Fs, n = %d, x = %f\n",
- pdata->name, pdata->n, pdata->x);
- /* Put new values in the data strucute. If CHILD was
- * created by a "spawn" function call, this data will
- * be available to the parent when child exits.
- * Notice that we have to use "movedata" to copy
- * "far" data in small or medium model. */
- p_s1 = (void far *)cname;
- p_s2 = (void far *)pdata->name;
- movedata(FP_SEG(p_s1), FP_OFF(p_s1),
- FP_SEG(p_s2), FP_OFF(p_s2), 6);
- pdata->n = 101;
- pdata->x = 999.99;
- exit(0);
- }